package yxy.game.pm2.module.arena.toparena;

import yxy.cherry.data.DataCenter;
import yxy.cherry.data.bean.dfsjingcai;

import java.util.Collection;
import java.util.Map;

/**
 * @ClassName TopAreanPlayer
 * @Author jingtao-zheng
 * @Date 2022/9/17 18:05
 * @Version 1.0
 **/
public class TopAreanStructure {
    private TopAreanHandle.TopAreanCode finalCode;//站位
    private TopAreanPlayer player1;
    private TopAreanPlayer player2;
    private TopAreanPlayer winner;//赢家
    private String record;// 录像码

    public TopAreanHandle.TopAreanCode getFinalCode() {
        return finalCode;
    }

    public void setFinalCode(TopAreanHandle.TopAreanCode finalCode) {
        this.finalCode = finalCode;
    }

    public TopAreanPlayer getPlayer1() {
        return player1;
    }

    public void setPlayer1(TopAreanPlayer player1) {
        this.player1 = player1;
    }

    public TopAreanPlayer getPlayer2() {
        return player2;
    }

    public void setPlayer2(TopAreanPlayer player2) {
        this.player2 = player2;
    }

    public TopAreanPlayer getWinner() {
        return winner;
    }

    public void setWinner(TopAreanPlayer winner) {
        this.winner = winner;
    }

    public String getRecord() {
        return record;
    }

    public void setRecord(String record) {
        this.record = record;
    }

    public dfsjingcai data(int groupid) {
        if (groupid == 0) {
            groupid = 9;
        }
        Map<String, dfsjingcai> allData = DataCenter.getAllData(dfsjingcai.class);
        Collection<dfsjingcai> dataValues = allData.values();
        if (groupid == 9) {
            switch (finalCode) {
                case F1256:
                case F3478:
                    return dataValues.stream().filter(v -> v.getType() == 2).findFirst().get();
                case FINAL:
                    return dataValues.stream().filter(v -> v.getType() == 1).findFirst().get();
                default:
                    return dataValues.stream().filter(v -> v.getType() == 3).findFirst().get();
            }
        } else {
            switch (finalCode) {
                case F1256:
                case F3478:
                    return dataValues.stream().filter(v -> v.getType() == 5).findFirst().get();
                case FINAL:
                    return dataValues.stream().filter(v -> v.getType() == 4).findFirst().get();
                default:
                    return dataValues.stream().filter(v -> v.getType() == 6).findFirst().get();
            }
        }
    }

    public TopAreanPlayer matchPlayer(String playercode) {
        if (getPlayer1().getPlayerCode().equals(playercode)) {
            return getPlayer1();
        } else {
            return getPlayer2();
        }
    }
}
